package com.rede.didiok.common.convert;

import com.rede.didiok.common.dto.community.UserMomentDto;
import com.rede.didiok.common.dto.rank.RankMemberDto;
import com.rede.didiok.common.enums.ResourceTypeEnum;
import com.rede.didiok.common.schema.AggEsDoc;

/**
 * EsAgg转换类
 */
public class AggEsDocConvert {

    /**
     * 转换榜单成员Agg
     * @param rankMember
     * @return
     */
    public static AggEsDoc convertRankMember(RankMemberDto rankMember) {
        AggEsDoc aggEsDoc = new AggEsDoc();
        aggEsDoc.setId(rankMember.getUid());
        aggEsDoc.setUid(rankMember.getUid());
        aggEsDoc.setOid(rankMember.getOid());
        aggEsDoc.setResourceType(ResourceTypeEnum.RANK_MEMBER.getType());
        aggEsDoc.setTitle(rankMember.getMemberName());
        aggEsDoc.setSummary(rankMember.getSummary());
        aggEsDoc.setContent(rankMember.getContent());
//        aggEsDoc.setAuthor(rankMember.getAuthor());
        aggEsDoc.setCreateUserUid(rankMember.getCreateUserUid());
        if (rankMember.getUser() != null) {
            aggEsDoc.setUser(rankMember.getUser());
        }
        aggEsDoc.setGradeUid(rankMember.getGradeUid());
        aggEsDoc.setGradeName(rankMember.getGradeName());
        if (rankMember.getCategory() != null) {
            aggEsDoc.setCatName(rankMember.getCategory().getCatName());
        }
        if (rankMember.getPhotoList() != null && rankMember.getPhotoList().size() > 0) {
            aggEsDoc.setPhotoUrl(rankMember.getPhotoList().get(0));
        }
        aggEsDoc.setCreateTime(rankMember.getCreateTime());
        aggEsDoc.setUpdateTime(rankMember.getUpdateTime());
        return aggEsDoc;
    }

    /**
     * 转换动态Agg
     * @param userMoment
     * @return
     */
    public static AggEsDoc convertMoment(UserMomentDto userMoment) {
        AggEsDoc aggEsDoc = new AggEsDoc();
        aggEsDoc.setId(userMoment.getUid());
        aggEsDoc.setUid(userMoment.getUid());
        aggEsDoc.setResourceType(ResourceTypeEnum.MOMENT.getType());
        aggEsDoc.setTitle("动态");
        aggEsDoc.setSummary(userMoment.getContent());
        aggEsDoc.setCreateUserUid(userMoment.getCreateUserUid());
        if (userMoment.getUser() != null) {
            aggEsDoc.setAuthor(userMoment.getUser().getNickname());
            aggEsDoc.setUser(userMoment.getUser());
        }
//        if (userMoment.getPhotoList() != null && userMoment.getPhotoList().size() > 0) {
//            aggEsDoc.setPhotoUrl(userMoment.getPhotoList().get(0));
//        }
        aggEsDoc.setContent(userMoment.getContent());
        aggEsDoc.setCreateTime(userMoment.getCreateTime());
        aggEsDoc.setUpdateTime(userMoment.getUpdateTime());
        return aggEsDoc;
    }


}
